package com.example.mybatis.controller;

import com.example.mybatis.domain.Book;
import com.example.mybatis.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/books")
public class BookController {
    @Autowired
    private IBookService bookService;

    @GetMapping
    public List<Book> getAll(){
        return bookService.selectAll();
    }


    @GetMapping("/{name}")
    public List<Book>  getByName( @PathVariable String name){
        return bookService.getByName(name);
    }
    @PostMapping
    public Boolean addBook(@RequestBody Book book){
        return bookService.addBook(book);
    }
    @DeleteMapping("/{id}")
    public Boolean delBook(@PathVariable Integer id){
        return bookService.delBook(id);
    }
    @PutMapping
    public Boolean delBook(@RequestBody Book book){
        return bookService.updateBook(book);
    }
}
